import java.io.*;
import java.util.*;
import java.lang.*;


public class  JLoader extends java.lang.ClassLoader
{
	public Class<?> findClass(String name)
		throws ClassNotFoundException
   	{
		try{
			byte[] buf = bytesForClass(name);
			return defineClass(name,buf,0,buf.length);
		} catch(IOException ex) {
			throw new ClassNotFoundException(ex.toString());
		}
	}

	protected byte[] bytesForClass(String name)
		throws IOException,ClassNotFoundException
   	{
		FileInputStream in = null;
		try{
			in = new FileInputStream(name+".class");
			int length = in.available();
			//System.out.println(length);
			if (length==0)
				throw new ClassNotFoundException(name);
			byte[] buf = new byte[length];
			in.read(buf);
			return buf;
		} finally {
			try{
			if (in!=null) 
				in.close();
			} catch (IOException ex) { }
		}
	}

	public static void main(String [] args) {
		JLoader loader = new JLoader();
		try{
			Class<? extends A> aaa 	
				= loader.findClass("AA").asSubclass(A.class);
			//System.out.println(people.newInstance());
			FileInputStream fin = new FileInputStream("junix");
			ObjectInputStream in = new ObjectInputStream(fin);
			//A aa = in.ReadObject();
			A aa = aaa.newInstance();
			aa.hello();
		} catch (ClassNotFoundException ex) { }
		catch(Exception e) {}
	}
}
